package com.yiqihui.my_shiro_jwt_redis.util;

import java.util.*;

/**
 * 通用工具
 * @author yqcao
 * @date 2020/09/13
 */
public class CommonUtil {


    public static boolean isNotNull(Object obj) {
        return !isNull(obj);
    }

    public static boolean isNull(Object obj) {
        if ( obj == null) {
            return true;
        }
        if (obj instanceof Long) {
            Long str = (Long) obj;
            if (str.equals(0L)) {
                return true;
            }
        } else if (obj instanceof String) {
            String str = (String) obj;
            if ("".equals(str.trim())) {
                return true;
            }
        } else if (obj instanceof Collection) {
            Collection c = (Collection) obj;
            if (c.isEmpty()) {
                return true;
            }
        } else if (obj instanceof Map) {
            Map map = (Map) obj;
            if (map.isEmpty()) {
                return true;
            }
        } else if (obj instanceof Iterator) {
            Iterator iter = (Iterator) obj;
            if (!iter.hasNext()) {
                return true;
            }
        } else if (obj instanceof Enumeration) {
            Enumeration em = (Enumeration) obj;
            if (!em.hasMoreElements()) {
                return true;
            }
        } else if (obj.getClass().isArray()) {
            Object[] objArr = (Object[]) obj;
            if (objArr.length <= 0) {
                return true;
            }
        } else {
            if ("".equals(obj.toString().trim())) {
                return true;
            }
        }
        return false;
    }

    public static boolean isEquals(Object obj1, Object obj2) {
        if (obj1 == null && obj2 == null) {
            return true;
        }
        if (obj1 != null) {
            return obj1.equals(obj2);
        }
        return false;
    }

    public static <E> long[] listToIds(List<E> list, String property) {
        Set<Long> idSet = new HashSet();
        Iterator var3 = list.iterator();

        while(var3.hasNext()) {
            Object e = var3.next();
            Object obj = QgBeanUtil.getPropertyValue(e, property);
            if (isNotNull(obj)) {
                idSet.add(Long.parseLong(obj.toString()));
            }
        }

        long[] ids = idSet.stream().mapToLong((t) -> {
            return t;
        }).toArray();
        return ids;
    }
}
